<?php

function smarty_block_stu($params, $content, &$smarty)
{
   if(empty($content))return;
   $limit =$params['row'];//显示条数
   $sex = isset($params['sex'])?$params['sex']:'';
   $where='';
   if(!empty($sex))
   	$where = " WHERE sex =".$sex;


    mysql_connect('localhost','root','');
    mysql_query('set names utf8');
    mysql_select_db('cw_test');
    
    $sql = "SELECT * FROM stu $where LIMIT $limit";
    $result = mysql_query($sql);
    $data=array();
    while($r = mysql_fetch_assoc($result)){
    		$data[]=$r;
    }
    $str='';
    foreach($data as $stu){
    		$tmp = $content;
    		foreach($stu as $name=>$value){
			$search='[$field.'.$name.']';
			$tmp=str_replace($search, $value, $tmp);

    		}
    		$str.=$tmp;
    }
    return $str;
}

?>
